<!DOCTYPE html>
<meta name="viewport" content="width=device-width, user-scalable=no">
<link rel="stylesheet" type="text/css" href="resources/tablet.css">
<script src="resources/perf_test_helper.js"></script>
<script src="resources/web_animations_api_check.js"></script>

<container id="container"></container>

<script>
var N = PerfTestHelper.getN(1000);
var duration = 1000;
var players = [];
var prevTime = null;

for (var i = 0; i < N; i++) {
  var target = document.createElement('target');
  container.appendChild(target);

  var player = target.animate([
    {opacity: 0},
    {opacity: 1},
  ], {
    duration: duration,
    iterations: Infinity,
  });
  if (player.pause) {
    player.pause();
  }
  players.push(player);
}

requestAnimationFrame(function setCurrentTime(time) {
  if (prevTime == null) {
    prevTime = time;
  }
  var delta = time - prevTime;
  players.forEach(function(player) {
    player.currentTime += delta;
  });
  prevTime = time;

  requestAnimationFrame(setCurrentTime);
});

PerfTestHelper.signalReady();
</script>
